package com.lanyou.esb.cook.proxy.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.RowMapper;

import com.lanyou.esb.cook.proxy.entity.Http;

/**
 * HTTP接口持久层
 * 
 * @author Davey.wu
 */
public class HttpDao extends BaseDao<Http> {
	RowMapper<Http> mapper = new RowMapper<Http>() {
		public Http mapRow(ResultSet rs, int rowNum) throws SQLException {
			Http rcd = new Http();
			rcd.setId(rs.getString("IF_HTTP_ID"));
			rcd.setSystemId(rs.getString("FIELD_SYSTEM_ID"));
			rcd.setSystemCode(rs.getString("SYSTEM_CODE"));
			rcd.setName(rs.getString("IF_NAME"));
			rcd.setCode(rs.getString("IF_CODE"));
			rcd.setIsPublic(rs.getString("IS_PUBLIC"));
			rcd.setAuthType(rs.getString("AUTH_TYPE"));
			rcd.setType(rs.getString("IF_TYPE"));
			rcd.setDesc(rs.getString("IF_DESC"));
			rcd.setPriUrl(rs.getString("IF_PRI_URL"));
			rcd.setPubUrl(rs.getString("IF_PUB_URL"));
			rcd.setVersion(rs.getString("IF_VERSION"));
			rcd.setStatus(rs.getString("IF_STATUS"));
			rcd.setMethod(rs.getString("IF_REQUEST"));
			rcd.setDataFormate(rs.getString("DATA_FORMATE"));
			rcd.setOvertimeTimes(rs.getInt("OVERTIME_TIMES"));
			rcd.setIsCost(rs.getString("IS_COST"));
			rcd.setRemark(rs.getString("REMARK"));
			rcd.setAuditStatus(rs.getString("AUDIT_STATUS"));
			rcd.setAuditRemark(rs.getString("AUDIT_REMARK"));
			rcd.setReqParaMess(rs.getString("REQUEST_PARA_MESS"));
			rcd.setRetParaMess(rs.getString("RETURN_PARA_MESS"));
			rcd.setIsIsolation(rs.getString("IS_ISOLATION"));
			rcd.setIsTrace(rs.getString("IS_TRACE"));
			rcd.setIsEnable(rs.getString("IS_ENABLE"));
			rcd.setCreator(rs.getString("CREATOR"));
			rcd.setCreatedDate(rs.getDate("CREATED_DATE"));
			rcd.setModifier(rs.getString("MODIFIER"));
			rcd.setLastUpdateDate(rs.getDate("LAST_UPDATED_DATE"));
			return rcd;
		}
	};

	@Override
	public List<Http> findAll() {
		String sql = "select * from  T_ESB_BU_IF_HTTP";
		List<Http> records = this.getJdbcTemplate().query(sql, mapper);
		return records;
	}

	@Override
	public Http find(Http http) {
		// 根据系统编码，接口编码，接口版本获取HTTP接口
		if (http == null || StringUtils.isBlank(http.getSystemCode())
				|| StringUtils.isBlank(http.getCode())
				|| StringUtils.isBlank(http.getVersion()))
			;
		String sql = "select * from  T_ESB_BU_IF_HTTP where SYSTEM_CODE=? and IF_CODE=? and IF_VERSION=?";
		Http record = this.getJdbcTemplate().queryForObject(sql, mapper,
				http.getSystemCode(), http.getCode(), http.getVersion());
		return record;
	}
}
